import { Global } from "../../../../../../com/gengine/global/Global";
import { Lv70NpcTalkData } from "../../data/Lv70NpcTalkData";
import { DisplayUtil } from "../../../../../common/DisplayUtil";
import { Lv70NpcTalkFaceData } from "./Lv70NpcTalkFaceData";
import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { Lv70NpcTalkTextParser } from "./Lv70NpcTalkTextParser";
import { ObjCreate } from "../../../common/ObjCreate";
import { Lv70NpcTalkMask } from "./Lv70NpcTalkMask";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
type int = number;
//class Lv70NpcTalkMaskText
    
    export  class Lv70NpcTalkMaskText /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            return;
        }

        public dispose(): void
        {
            if (this._timerId1 > 0) 
            {
                flash.utils.clearTimeout(this._timerId1);
                this._timerId1 = -1;
            }
            if (this._timerId2 > 0) 
            {
                flash.utils.clearTimeout(this._timerId2);
                this._timerId2 = -1;
            }
            Global.stage.removeEventListener(flash.events.MouseEvent.CLICK, this.clickNextStep);
            return;
        }

        public get data(): Lv70NpcTalkData
        {
            return this._data;
        }

        public resize(arg1: int): void
        {
            this._mask.reWidth(arg1);
            this._txtTalk.width = arg1;
            return;
        }

        public show(arg1: Lv70NpcTalkData, arg2: Function): void
        {
            this._data = arg1;
            this._onEnd = arg2;
            this._isShowingStage = false;
            var loc1=this._txtTalk.defaultTextFormat;
            loc1.size = this._data.talkFontSize;
            loc1.leading = this._data.talkFontLeading;
            this._txtTalk.defaultTextFormat = loc1;
            this._txtTalk.textColor = 11795964;
            this._txtTalk.width = this._data.rowWidth;
            this._txtTalk.text = "";
            this._timerId1 = flash.utils.setTimeout(this.onPopupEnd, this._data.popupTime * 1000);
            Global.stage.addEventListener(flash.events.MouseEvent.CLICK, this.clickNextStep);
            return;
        }

        /* internal  */clickNextStep(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._isShowingStage) 
            {
                flash.utils.clearTimeout(this._timerId2);
                this.onShowEnd();
            }
            else 
            {
                flash.utils.clearTimeout(this._timerId1);
                this.onPopupEnd();
                this._mask.finishRightNow();
            }
            return;
        }

        public stopShow(): void
        {
            flash.utils.clearTimeout(this._timerId1);
            flash.utils.clearTimeout(this._timerId2);
            this._mask.stop();
            Global.stage.removeEventListener(flash.events.MouseEvent.CLICK, this.clickNextStep);
            this._isShowingStage = false;
            return;
        }

        /* internal  */onPopupEnd(): void
        {
            var loc1=this.textParser.parse(this._data.talk, this._data.talkFontLeading, this._data.talkFontSize, this._data.rowWidth);
            this._txtTalk.htmlText = String(loc1[0]);
            DisplayUtil.removeAllChild(this._facesContainer);
            this._facesContainer.addChild(this.getFaceSprite(loc1[1] as Array<any>));
            this._mask.reInit(this._data, this._txtTalk, this.onRollingEnd);
            this._isShowingStage = false;
            return;
        }

        /* internal  */getFaceSprite(arg1: Array<any>): Object /* flash.display.Sprite */
        {
            var loc1=null;
            var loc3=null;
            var loc4=null;
            loc1 = new Object /* flash.display.Sprite */();
            var loc2=0;
            while (arg1 && loc2 < arg1.length) 
            {
                loc3 = arg1[loc2] as Lv70NpcTalkFaceData;
                (loc4 = GlobalClass.getInstance("a" + loc3.faceId.toString()) as Object /* flash.display.MovieClip */).x = loc3.faceX;
                loc4.y = loc3.faceY;
                loc4.mouseEnabled = true;
                loc4.buttonMode = true;
                loc1.addChild(loc4);
                ++loc2;
            }
            return loc1;
        }

        /* internal  */onRollingEnd(): void
        {
            this._isShowingStage = true;
            this._timerId2 = flash.utils.setTimeout(this.onShowEnd, this._data.showTime);
            return;
        }

        /* internal  */get textParser(): Lv70NpcTalkTextParser
        {
            if (this._txtParser == null) 
            {
                this._txtParser = new Lv70NpcTalkTextParser();
            }
            return this._txtParser;
        }

        /* internal  */onShowEnd(): void
        {
            this._isShowingStage = false;
            flash.utils.clearTimeout(this._timerId1);
            flash.utils.clearTimeout(this._timerId2);
            Global.stage.removeEventListener(flash.events.MouseEvent.CLICK, this.clickNextStep);
            if (this._onEnd != null) 
            {
                this._onEnd.apply();
                this._onEnd = null;
            }
            return;
        }

        /* internal  */initView(): void
        {
            this._textFaceContainer = new Object /* flash.display.Sprite */();
            this.addChild(this._textFaceContainer);
            this._txtTalk = ObjCreate.createGTextField("", 0, 0, 200, 500, this._textFaceContainer);
            this._txtTalk.multiline = true;
            this._txtTalk.wordWrap = true;
            this._txtTalk.mouseEnabled = false;
            this._txtTalk.mouseWheelEnabled = false;
            this._facesContainer = new Object /* flash.display.Sprite */();
            this._textFaceContainer.addChild(this._facesContainer);
            this._mask = new Lv70NpcTalkMask();
            this._textFaceContainer.mask = this._mask;
            this.addChild(this._mask);
            return;
        }

        /* internal */ /* var */_data: Lv70NpcTalkData;

        /* internal */ /* var */_txtTalk: GTextFiled;

        /* internal */ /* var */_mask: Lv70NpcTalkMask;

        /* internal */ /* var */_onEnd: Function;

        /* internal */ /* var */_timerId1: int;

        /* internal */ /* var */_timerId2: int;

        /* internal */ /* var */_txtParser: Lv70NpcTalkTextParser;

        /* internal */ /* var */_facesContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_textFaceContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_isShowingStage: Boolean;
    }
